﻿using System;
using System.Data;
using System.Collections.Generic;
using HsTec.Mobile.Green.Model;
namespace HsTec.Mobile.Green.BLL
{
    /// <summary>
    /// 业务逻辑类SingleProject 的摘要说明。
    /// </summary>
    public class SingleProjectBLL
    {
        private readonly HsTec.Mobile.Green.DAL.SingleProjectDAL dal = new HsTec.Mobile.Green.DAL.SingleProjectDAL();
        public SingleProjectBLL()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string sp_ids)
        {
            return dal.Exists(sp_ids);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(HsTec.Mobile.Green.Model.SingleProject model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(HsTec.Mobile.Green.Model.SingleProject model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public int Delete(string sp_ids)
        {
            return dal.Delete(sp_ids);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public HsTec.Mobile.Green.Model.SingleProject GetModel(int sp_id)
        {

            return dal.GetModel(sp_id);
        }

        public HsTec.Mobile.Green.Model.SingleProjectEntity GetModelEntity(int sp_id)
        {

            return dal.GetModelEntity(sp_id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataView GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataView GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<HsTec.Mobile.Green.Model.SingleProject> GetModelList(string strWhere)
        {
            DataView ds = dal.GetList(strWhere);
            return DataTableToList(ds.Table);
        }

        public List<HsTec.Mobile.Green.Model.SingleProjectEntity> GetModelListEntity(string strWhere)
        {
            DataView ds = dal.GetListEntity(strWhere);
            return DataTableToListEntity(ds.Table);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<HsTec.Mobile.Green.Model.SingleProject> DataTableToList(DataTable dt)
        {
            List<HsTec.Mobile.Green.Model.SingleProject> modelList = new List<HsTec.Mobile.Green.Model.SingleProject>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                HsTec.Mobile.Green.Model.SingleProject model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new HsTec.Mobile.Green.Model.SingleProject();
                    if (dt.Rows[n]["sp_id"].ToString() != "")
                    {
                        model.sp_id = int.Parse(dt.Rows[n]["sp_id"].ToString());
                    }
                    model.spno = dt.Rows[n]["spno"].ToString();
                    model.listno = dt.Rows[n]["listno"].ToString();
                    model.volumeno = dt.Rows[n]["volumeno"].ToString();
                    model.spname = dt.Rows[n]["spname"].ToString();
                    model.fix = dt.Rows[n]["fix"].ToString();
                    model.cooperation = dt.Rows[n]["cooperation"].ToString();
                    model.design = dt.Rows[n]["design"].ToString();
                    if (dt.Rows[n]["person"].ToString() != "")
                    {
                        model.person = int.Parse(dt.Rows[n]["person"].ToString());
                    }
                    if (dt.Rows[n]["designer"].ToString() != "")
                    {
                        model.designer = int.Parse(dt.Rows[n]["designer"].ToString());
                    }
                    if (dt.Rows[n]["proofreader"].ToString() != "")
                    {
                        model.proofreader = int.Parse(dt.Rows[n]["proofreader"].ToString());
                    }
                    if (dt.Rows[n]["reviewer"].ToString() != "")
                    {
                        model.reviewer = int.Parse(dt.Rows[n]["reviewer"].ToString());
                    }
                    if (dt.Rows[n]["charger"].ToString() != "")
                    {
                        model.charger = int.Parse(dt.Rows[n]["charger"].ToString());
                    }
                    if (dt.Rows[n]["head"].ToString() != "")
                    {
                        model.head = int.Parse(dt.Rows[n]["head"].ToString());
                    }
                    if (dt.Rows[n]["branchreviewer"].ToString() != "")
                    {
                        model.branchreviewer = int.Parse(dt.Rows[n]["branchreviewer"].ToString());
                    }
                    if (dt.Rows[n]["Standardization"].ToString() != "")
                    {
                        model.Standardization = int.Parse(dt.Rows[n]["Standardization"].ToString());
                    }
                    if (dt.Rows[n]["Investment"].ToString() != "")
                    {
                        model.Investment = decimal.Parse(dt.Rows[n]["Investment"].ToString());
                    }
                    if (dt.Rows[n]["projectcost"].ToString() != "")
                    {
                        model.projectcost = decimal.Parse(dt.Rows[n]["projectcost"].ToString());
                    }
                    if (dt.Rows[n]["designfees"].ToString() != "")
                    {
                        model.designfees = decimal.Parse(dt.Rows[n]["designfees"].ToString());
                    }
                    model.accessories = dt.Rows[n]["accessories"].ToString();
                    if (dt.Rows[n]["surveydate"].ToString() != "")
                    {
                        model.surveydate = DateTime.Parse(dt.Rows[n]["surveydate"].ToString());
                    }
                    if (dt.Rows[n]["tp_id"].ToString() != "")
                    {
                        model.tp_id = int.Parse(dt.Rows[n]["tp_id"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        public List<HsTec.Mobile.Green.Model.SingleProjectEntity> DataTableToListEntity(DataTable dt)
        {
            List<HsTec.Mobile.Green.Model.SingleProjectEntity> modelList = new List<HsTec.Mobile.Green.Model.SingleProjectEntity>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                HsTec.Mobile.Green.Model.SingleProjectEntity model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new HsTec.Mobile.Green.Model.SingleProjectEntity();
                    if (dt.Rows[n]["sp_id"].ToString() != "")
                    {
                        model.sp_id = int.Parse(dt.Rows[n]["sp_id"].ToString());
                    }
                    model.spno = dt.Rows[n]["spno"].ToString();
                    model.listno = dt.Rows[n]["listno"].ToString();
                    model.volumeno = dt.Rows[n]["volumeno"].ToString();
                    model.spname = dt.Rows[n]["spname"].ToString();
                    model.fix = dt.Rows[n]["fix"].ToString();
                    model.cooperation = dt.Rows[n]["cooperation"].ToString();
                    model.design = dt.Rows[n]["design"].ToString();
                    if (dt.Rows[n]["person"].ToString() != "")
                    {
                        model.person = int.Parse(dt.Rows[n]["person"].ToString());
                    }
                    if (dt.Rows[n]["designer"].ToString() != "")
                    {
                        model.designer = int.Parse(dt.Rows[n]["designer"].ToString());
                    }
                    if (dt.Rows[n]["proofreader"].ToString() != "")
                    {
                        model.proofreader = int.Parse(dt.Rows[n]["proofreader"].ToString());
                    }
                    if (dt.Rows[n]["reviewer"].ToString() != "")
                    {
                        model.reviewer = int.Parse(dt.Rows[n]["reviewer"].ToString());
                    }
                    if (dt.Rows[n]["charger"].ToString() != "")
                    {
                        model.charger = int.Parse(dt.Rows[n]["charger"].ToString());
                    }
                    if (dt.Rows[n]["head"].ToString() != "")
                    {
                        model.head = int.Parse(dt.Rows[n]["head"].ToString());
                    }
                    if (dt.Rows[n]["branchreviewer"].ToString() != "")
                    {
                        model.branchreviewer = int.Parse(dt.Rows[n]["branchreviewer"].ToString());
                    }
                    if (dt.Rows[n]["Standardization"].ToString() != "")
                    {
                        model.Standardization = int.Parse(dt.Rows[n]["Standardization"].ToString());
                    }
                    if (dt.Rows[n]["Investment"].ToString() != "")
                    {
                        model.Investment = decimal.Parse(dt.Rows[n]["Investment"].ToString());
                    }
                    if (dt.Rows[n]["projectcost"].ToString() != "")
                    {
                        model.projectcost = decimal.Parse(dt.Rows[n]["projectcost"].ToString());
                    }
                    if (dt.Rows[n]["designfees"].ToString() != "")
                    {
                        model.designfees = decimal.Parse(dt.Rows[n]["designfees"].ToString());
                    }
                    model.accessories = dt.Rows[n]["accessories"].ToString();
                    if (dt.Rows[n]["surveydate"].ToString() != "")
                    {
                        model.surveydate = DateTime.Parse(dt.Rows[n]["surveydate"].ToString());
                    }
                    if (dt.Rows[n]["tp_id"].ToString() != "")
                    {
                        model.tp_id = int.Parse(dt.Rows[n]["tp_id"].ToString());
                    }
                    model.branchreviewername = dt.Rows[n]["branchreviewername"].ToString();
                    model.chargername = dt.Rows[n]["chargername"].ToString();
                    model.designername = dt.Rows[n]["designername"].ToString();
                    model.headname = dt.Rows[n]["headname"].ToString();
                    model.personname = dt.Rows[n]["personname"].ToString();
                    model.proofreadername = dt.Rows[n]["proofreadername"].ToString();
                    model.reviewername = dt.Rows[n]["reviewername"].ToString();
                    model.Standardizationname = dt.Rows[n]["Standardizationname"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataView GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

